package com.ai.planttrees.controller;


import com.ai.planttrees.model.PlantRecord;
import com.ai.planttrees.service.PlantService;
import com.ai.planttrees.service.RuleTitleService;
import com.ai.planttrees.util.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* Created by CodeGenerator on 2018/04/27.
*/
@Api(value = "种树接口",tags = {"种树记录管理"})
@RestController
@RequestMapping("/plant")
public class PlantController {
    @Resource
    private PlantService plantService;
    @Resource
    private RuleTitleService ruleTitleService;

    @ApiOperation(value = "种树" ,notes = "返回结果")
    @PutMapping("/")
    public synchronized Result addPlantRecord(@ApiParam("用户活动主键") @RequestParam("userId") String userId, @ApiParam("种树类型主键") @RequestParam("plantId") Integer plantId){
        Map rs = ruleTitleService.isOverdue();
        if(!(boolean)rs.get("code")){
            return Result.fail((String) rs.get("msg"));
        }
        PlantRecord plantRecord = new PlantRecord();
        plantRecord.setUserId(userId);
        plantRecord.setPlantId(plantId);
        return plantService.addPlantRecord(plantRecord);
    }

    @ApiOperation(value = "查询用户种树信息（plant集合）" ,notes = "返回结果")
    @PostMapping("/userId/")
    public Result selPlantRecordByUserId(@ApiParam("用户活动主键") @RequestParam("userId") String userId,@ApiParam("页数") @RequestParam("page") Integer page){
        return plantService.selByUserId(userId,page);
    }



}
